import { DatabaseHelper } from './DatabaseHelper.js';

let myHandler = async function (event, context, callback, logger) {
  logger.info(JSON.stringify(event))
  let userid: string = event.body ? JSON.parse(event.body).userId : event.userId;
  let result;
  try {
    const databaseHelper = new DatabaseHelper(context, logger);
    if (!userid) {
      callback({
        code: 1,
        message: 'userId can not empty',
        data: null,
      });
    }
    result = await databaseHelper.getLitAchieves(userid);
    if (result) {
      callback({
        code: 0,
        message: '请求成功',
        data: result,
      });
    } else {
      callback({
        code: 1,
        message: '操作失败',
        data: null,
      });
    }
  } catch (err) {
    logger.error("func error:" + err.message + " stack:" + err.stack);
    callback({
      code: 3,
      message: '操作失败',
      data: err,
    });
  }
};

export { myHandler };